#ifndef UARTWORK_H
#define UARTWORK_H

#include <QByteArray>

#include "uartcfg.h"
#include <QDebug>
#include <QObject>
#include <QSerialPort>
#include <QThread>
#include <QTimer>

class uartWork : public QObject {
  Q_OBJECT
public:
  explicit uartWork(comcfg_t);
  ~uartWork();
public slots:
  void updateComCfg(comcfg_t);
  void startThread();
  void stopThread();
  void writeData(QByteArray);

private slots:
  void readyRead();
  // void errorString();
  void openUart();
  void errorOccurred(QSerialPort::SerialPortError error);
  void timerOut();
signals:
  /* 打开成功发送 true,失败 false */
  void openError(bool);
  void readyread(QByteArray);
  void errOccurred(QString);

private:
  bool isConnectFlag;
  bool openFlag;
  QTimer *rcvDataTimer;
  comcfg_t currentCfg;
  QSerialPort *currSerial;
  QThread *currThread;
  QByteArray sendArray;
};

#endif // UARTWORK_H
